package com.taplinker.client.im.rpc;

import java.util.ArrayList;
import java.util.List;

import android.os.Handler;
import android.os.Message;

import com.taplinker.client.im.rpc.response.Cmd1001;
import com.taplinker.client.im.rpc.response.Cmd1003;
import com.taplinker.client.im.rpc.response.Cmd1004;
import com.taplinker.client.im.rpc.response.Cmd1005;
import com.taplinker.client.im.rpc.response.Cmd1006;
import com.taplinker.client.im.rpc.response.Cmd1007;
import com.taplinker.client.im.rpc.response.Cmd1008;
import com.taplinker.client.im.rpc.response.Cmd1011;
import com.taplinker.client.im.rpc.response.Cmd1012;
import com.taplinker.client.im.rpc.response.Cmd1013;
import com.taplinker.client.im.rpc.response.Cmd1017;
import com.taplinker.client.im.rpc.response.ImResponse;
import com.taplinker.core.rpc.Result;

public class ReceiveHandler extends Handler {

	public List<ImResponse> responseList = new ArrayList<ImResponse>();
	
	{
		responseList.add(new Cmd1003());
		responseList.add(new Cmd1004());
		responseList.add(new Cmd1005());
		responseList.add(new Cmd1006());
		responseList.add(new Cmd1007());
		responseList.add(new Cmd1011());
		responseList.add(new Cmd1012());
		responseList.add(new Cmd1013());
		responseList.add(new Cmd1008());
		responseList.add(new Cmd1001());
		responseList.add(new Cmd1017());
	}
	
	@Override
	public void handleMessage(Message msg) {
		super.handleMessage(msg);
		IMMessageResponse response = (IMMessageResponse)msg.obj;
		
		for(ImResponse cmd : responseList) {
			if(cmd.getCommand().equals(response.getMessage().getType())) {
				Result result = new Result();
				result.object = response.getMessage().getBody();
				cmd.yes(result);
			}
		}
	}
}
